//
//  Status.swift
//  weibo
//
//  Created by 陈伟 on 15/10/19.
//  Copyright © 2015年 陈伟. All rights reserved.
//

import UIKit

class Status: NSObject {
    
    
    /// 微博ID
    var id: Int = 0
    /// 微博信息内容
    var text: String?
    /// 微博创建时间
    var created_at: String?
    /// 微博来源
    var source: String?
    
    //略缩图数组 thumbnail_pic
    var pic_urls: [[String: String]]?
    // 用户模型
    var user: User?
    
    //转发微博的字段
    var retweeted_status: Status?
    
    //字典转模型方法
    init(dict: [String: AnyObject]){
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    //因User同样为字典  要进行一次字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            if let dict = value as? [String: AnyObject] {
                user = User(dict: dict)
            }
            return
        }
        if key == "retweeted_status" {
            guard let retweeted = value else {
                return
            }
            retweeted_status = Status(dict: retweeted as! [String : AnyObject])
            return
        }
        super.setValue(value, forKey: key)
    }
    
    //防止报错
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
    }
    
    override var description: String{
    
        let keys = ["id", "text", "created_at", "source", "pic_urls", "retweeted_status"]
        return dictionaryWithValuesForKeys(keys).description
    }
}
